package com.phil.tuangou.lashou;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.phi.tuangou.bean.CityBean;
import com.phil.tuangou.main.activtiy.ITuanGou;
import com.phil.xml.parse.LashouCityDetailHandler;
import com.phil.xml.parse.LashouCityHandler;

public class MyLaShouNet implements ITuanGou {

	private static final String CITY_LIST_URL = "http://open.client.lashou.com/list/cities/";
	private static final String CITY_DETAIL_INFO_URL = "http://open.client.lashou.com/list/goods/cityid/";

	@SuppressWarnings("unchecked")
	public List getInfo(CityBean city) throws SAXException, IOException,
			ParserConfigurationException {
		SAXParserFactory sf = SAXParserFactory.newInstance();
		sf.setNamespaceAware(true);
		SAXParser sp = sf.newSAXParser();

		LashouCityDetailHandler lashoudetailsax = new LashouCityDetailHandler();

		// sp.parse(new InputSource(Uri.parse(CITY_LIST_URL)),testsax);
		// Uri uri = Uri.parse(CITY_LIST_URL);
		System.out.println("url == " + CITY_DETAIL_INFO_URL + city.getCityId());
		InputSource is = new InputSource(CITY_DETAIL_INFO_URL
				+ city.getCityId());
		is.setEncoding("UTF-8");
		sp.parse(is, lashoudetailsax);

		return lashoudetailsax.getList();
	}

	public List<CityBean> getCitys() throws SAXException, IOException,
			ParserConfigurationException {

		SAXParserFactory sf = SAXParserFactory.newInstance();
		SAXParser sp = sf.newSAXParser();

		LashouCityHandler lashousax = new LashouCityHandler();

		// sp.parse(new InputSource(Uri.parse(CITY_LIST_URL)),testsax);
		// Uri uri = Uri.parse(CITY_LIST_URL);
		InputSource is = new InputSource(CITY_LIST_URL);
		is.setEncoding("UTF-8");
		sp.parse(is, lashousax);

		return lashousax.getList();
	}

}
